import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.security.MessageDigest;

import javax.swing.*;


public class AjoutBox extends JFrame implements ActionListener{
	
	
	private String nomBox;
	private JPanel panelInfos;
    private JPanel panelButton;
	private JButton butEnregistrer;
	private JButton butAnnuler;
	private JLabel nomBoxLab;
	private JTextField nomBoxTxt;

	
	
	public AjoutBox(){
		this.setBounds(450,250,350,200);
		this.initPanels();
		this.setTitre();
	}
		
		
		
	public void initPanels( ){					
		Container contenu= this.getContentPane();
		contenu.setLayout(null);
						
		this.initPanelInfos();
		this.initPanelButtons();
					
		contenu.add(this.panelInfos);
		contenu.add(this.panelButton) ;
					
		this.setBoundsPanels();
	
	}
	
		
	public void setBoundsPanels(){
		this.panelInfos.setBounds(60, 40, 210, 50);
		this.panelButton.setBounds(65, 120, 200, 70);
		
	}	
	
	
	public void initPanelInfos(){	
		this.panelInfos = new JPanel();
		this.nomBox = new String("");
		this.nomBoxLab = new JLabel("Nom box");
		this.nomBoxTxt = new JTextField("");
	
		this.panelInfos.setLayout(new GridLayout(2,2));
		this.panelInfos.add(this.nomBoxLab);
		this.panelInfos.add(this.nomBoxTxt);	
	}
	
	
	public void initPanelButtons(){
		this.panelButton = new JPanel();
		this.butEnregistrer = new JButton("Enregistrer");
		this.butAnnuler = new JButton("Annuler");
		
		this.panelButton.add(this.butEnregistrer);
		this.panelButton.add(this.butAnnuler);
		this.butEnregistrer.setBounds(0,0,80,20);
		this.butAnnuler.setBounds(0,0,80,20);
		this.butEnregistrer.addActionListener(this);
		this.butAnnuler.addActionListener(this);	
	}

	
	public void setTitre() {
		this.setTitle("AjoutBox");
	}

	public  void annule(){
		this.dispose();
	
	}
	


	public void actionPerformed(ActionEvent e) {
		if(e.getSource() == this.butEnregistrer){
			
			if(nomBoxTxt.getText().equals(""))
				JOptionPane.showMessageDialog(this,"Vous n'avez rentré aucun nom.", "Attention", JOptionPane.OK_OPTION,new ImageIcon("./images/icon/warn.png"));
			
			else{
				this.nomBox = this.nomBoxTxt.getText();
				/*Box b = new Box(this.nomBox);
				if(!main.testUpdate)
					JOptionPane.showMessageDialog(this,"Le box n'a pas pu �tre ajoutŽ!", "Attention", JOptionPane.OK_OPTION,new ImageIcon("./images/icon/warn.png"));
				else{
					JOptionPane.showMessageDialog(this,"Le box a bien ŽtŽ ajoutŽ", "Model Manager", JOptionPane.OK_OPTION,new ImageIcon("./images/icon/ok.png"));
				this.dispose();
				RechercheModele m = new RechercheModele();*/
				
				}
		}
		
		if (e.getSource() == this.butAnnuler){
			int rep = JOptionPane.showConfirmDialog(this, "Etes-vous sûr de vouloir annuler ?", "Confirmation annulation",JOptionPane.YES_NO_OPTION);
			if (rep == JOptionPane.OK_OPTION)
				this.annule();
		}

	}
	
	public String getNomBox(){
		return this.nomBox;
	}
	
	public void setNomBox(String nomBox) {
		this.nomBox = nomBox;
	}
	
	
	public static void main (String[] args){
		
		AjoutBox add = new AjoutBox();
		add.setVisible(true);
		
	}
	
}	